      !=======================================================================
      !> @file main.f90
      !> @brief Interface with the AGAv1 implementation
      !> @details This is an example of the interface, the user must
      !! write/modify his/her own to use the AGAv1 program.
      !> @authors Ary Rodriguez-Gonzalez & Alejandro Esquivel
      !> @date 23/Jun/2011
      !
      ! Copyright (c) 2011 Ary Rodriguez-Gonzalez & Alejandro Esquivel
      !
      ! This file is part of AGA-V1.
      !
      ! AGA-V1 is free software; you can redistribute it and/or modify
      ! it under the terms of the GNU General Public License as published by
      ! the Free Software Foundation; either version 3 of the License, or
      ! (at your option) any later version.
      !
      ! This program is distributed in the hope that it will be useful,
      ! but WITHOUT ANY WARRANTY; without even the implied warranty of
      ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      ! GNU General Public License for more details.
      ! You should have received a copy of the GNU General Public License
      ! along with this program.  If not, see http://www.gnu.org/licenses/.
      !=======================================================================
      !> @brief Main program/interface with AGAv1
      !> @details This is a test example of a main program that initializes
      !! MPI (if enabled in makefile), reads data from (ObsData.dat), and
      !! calls AGAv1 to find the solution to....
      !>@ todo Terminar descripcion del main program.
      program test
        !
        ! -------------------------------------------------------------------------
        !
        use agav1                     ! located in aga-v1.f90 file
        use numgaus       ! located in extfunc.f90
        use input                     ! located in extfunc.f90
        use exfunc            ! located in extfunc.f90
        use func                      ! located in modules.f90
        use mpi_module        ! located in modules.f90
        !
        implicit none
        real, dimension(:), allocatable :: xobs,yobs,ysigma
        real, dimension(:), allocatable :: q,delta
      !  real, dimension(:), allocatable :: yfit,gfit
      !  real, dimension(:), allocatable :: cold,dold
      !  real,dimension(:),allocatable :: cc,dd
      !  real :: sigman,sigfit,fluxm,gmed,noise,nflux
        integer :: npar,ndata,i
        !
        !*********************************************************************
#ifdef MPIP
        ! MPI initialization (only if MPI defined in makefile)
        call mpi_init(err)
        call mpi_comm_rank (mpi_comm_world,rank,err)
        call mpi_comm_size (mpi_comm_world,np,err)
        if(rank.eq.master) then
           print * ,'*****************************************'
           print '(a,i3,a)',' *  running using mpi on ', np , ' processors  *'
           print * ,'*****************************************'
        endif
#endif
        !*********************************************************************
        !
        !
#ifdef MPIP
        do i=0,np-1
           if (rank.eq.i) then
#endif
              call ReadData(xobs,yobs,ysigma,ndata)
#ifdef MPIP
           endif
           call mpi_barrier (mpi_comm_world, err)
        enddo
#endif
        !  
        !
        call Algorithm(xobs,yobs,ysigma,q,delta,npar,ndata)
        !
        if (rank .eq. master) then
           print*,'-------------- Final Fit ------------------'
           !
           do i=1,2
              print*,'q(',i,'):',q(i),'delta(',i,'):',delta(i)
           enddo
           !
        endif
        !*********************************************************************
#ifdef MPIP
        call mpi_finalize(err)
#endif
        !*********************************************************************
        ! -------------------------------------------------------------------------
        !
      end program test
